#!/usr/bin/env python
'''
Main program for iQmerge
'''
#########################################################################################
#                                                                                       #
# iQmerge software tool for merging CID and HCD scans for iTRAQ/TMT type experiments    #                                                                            #
# Written by Ashoka D. Polpitiya                                                        #
# for the Translational Genomics Research Institute (TGen), Phoenix, AZ                 #
#                                                                                       #
# Copyright 2011, Translational Genomics Research Institute                             #
# E-mail: ashoka@tgen.org                                                               #
# Website: http://iqmerge.googlecode.com                                                #
# --------------------------------------------------------------------------------------#
#                                                                                       #
# Licensed under the Apache License, Version 2.0 (the "License");                       #
# you may not use this file except in compliance with the License.                      #
# You may obtain a copy of the License at                                               #
#                                                                                       #
#       http://www.apache.org/licenses/LICENSE-2.0                                      #
#                                                                                       #
# Unless required by applicable law or agreed to in writing, software                   #
# distributed under the License is distributed on an "AS IS" BASIS,                     #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.              #
# See the License for the specific language governing permissions and                   #
# limitations under the License.                                                        #
#                                                                                       #
#########################################################################################

from mzXML.FromMzXML import FromMzXML
from mzXML.ToMzXML import ToMzXML
import os.path

if __name__ == '__main__':
    '''
    #filename = 'C:/Ashoka/Research/iQmerge/Data/CAR_tmtSlice2.mzXML'
    #filename = 'C:/Ashoka/Research/iQmerge/Data/CAR_tmtSlice_centroided.mzXML'
    filename = "D:/Research/iQmerge/Data/CAR_tmtSlice_centroided.mzXML"
    #filename = "D:/Research/iQmerge/Data/CAR_tmtSlice2.mzXML"
    mzXMLreadHandle = FromMzXML(filename)
    #meta = mzXMLreadHandle.getMsRunMetaData()
    #mzXMLwriteHandle = ToMzXML(mzXMLreadHandle,"C:/Ashoka/Research/iQmerge/Data/CAR_tmtSlice_centroided_iq.mzXML")
    mzXMLwriteHandle = ToMzXML(mzXMLreadHandle,"D:/Research/iQmerge/Data/tstFile.mzXML")
    mzXMLwriteHandle.write()
    print "Done..."
    '''
    
    fileList = 'D:/Research/iQmerge/Data/fileList1.txt'
    fh = open(fileList, 'r')
    mzXMLFiles = fh.readlines()
    mzXMLFiles = [i.strip('\n') for i in mzXMLFiles]
    fh.close()
    
    for f in mzXMLFiles:
        xmlOut = os.path.splitext(f)[0]+'_iqm.mzXML'
        mzXMLreadHandle = FromMzXML(f)
        #meta = mzXMLreadHandle.getMsRunMetaData()
        #mzXMLwriteHandle = ToMzXML(mzXMLreadHandle,"C:/Ashoka/Research/iQmerge/Data/CAR_tmtSlice_centroided_iq.mzXML")
        mzXMLwriteHandle = ToMzXML(mzXMLreadHandle,xmlOut)
        mzXMLwriteHandle.write()
        print "Done..." 
    

